package com.ruoyi.applet.controller;

import java.util.List;
import java.io.IOException;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.applet.utli.TokenByUsrId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.applet.domain.SearchHistory;
import com.ruoyi.applet.service.ISearchHistoryService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 搜索历史记录Controller
 * 
 * @author ruoyi
 * @date 2024-11-19
 */
@RestController
@RequestMapping("/applet")
public class SearchHistoryController extends BaseController {
    @Resource
    private ISearchHistoryService searchHistoryService;

    @RequestMapping("/searchList")
    public Object selectSearchList(@RequestParam("token") String token){
        return searchHistoryService.selectAllBySearchUsrIdList(TokenByUsrId.tokenByUsrId(token));
    }

    @RequestMapping("/searchInsert")
    public Object insertSearch(@RequestParam("token") String token,@RequestParam("searchText") String searchText){
        if(searchHistoryService.selectAllBySearchUsrIdInteger(TokenByUsrId.tokenByUsrId(token),searchText) < 1){
            return searchHistoryService.insertAll(TokenByUsrId.tokenByUsrId(token),searchText);
        }
        return true;
    }

    @RequestMapping("/searchDelete")
    public Object deleteSearch(@RequestParam("token") String token,@RequestParam("searchId") Long searchId){
        return searchHistoryService.deleteBySearchUsrIdBoolean(TokenByUsrId.tokenByUsrId(token),searchId);
    }
}
